﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Collections.ObjectModel;
using System.Globalization;

namespace University.Workshop.Business
{
    public static class GiftCardManager
    {
        public static GiftCard NewGiftCard(long userIdSender, long userIdRecipient, float quantity, string currency, string notification, string available)
        {
            GiftCard giftCard = new GiftCard 
            {
                UserIdSender = userIdSender,
                UserIdRecipient = userIdRecipient,
                Quantity = quantity,
                Currency = currency,
                Notification = notification,
                Available = available
            };
            giftCard = GiftCardDataAccess.NewGiftCard(giftCard);
            return giftCard;
        }

        public static GiftCard ModifyGiftCard(long userIdSender, long userIdRecipient, float quantity, string currency, string notification, string available)
        {
            GiftCard giftCard = new GiftCard
            {
                UserIdSender = userIdSender,
                UserIdRecipient = userIdRecipient,
                Quantity = quantity,
                Currency = currency,
                Notification = notification,
                Available = available
            };
            giftCard = GiftCardDataAccess.ModifyGiftCard(giftCard);
            return giftCard;
        }
        public static Collection<Product> GridGiftLoad()
        {
            return ProductDataAccess.ViewProductsDealsGifts();
        }
        public static bool IsGiftCard(string productName)
        {
            if (!string.IsNullOrEmpty(productName))
            {
                string prodNameL = productName.ToLower(CultureInfo.CurrentCulture);

                String[] productNameSplit = SearchProductsManager.SeparateWords(prodNameL);//Re-use code to split a string

                foreach (string word in productNameSplit)
                {
                    if (word.Contains("giftcard"))
                        return true;
                }
            }
            return false;
        }

        public static bool UserHasGiftCard(User user)
        {
            return GiftCardDataAccess.UserHasNewCredit(user);
        }
        public static GiftCard GetGiftCardByRecipientId(long recipientId)
        {
            return GiftCardDataAccess.GetGiftCardByRecipientId(recipientId);
        }
        public static void ChangeNotificationToYes(GiftCard giftCard)
        {
            GiftCardDataAccess.NotificationGiftCardToYes(giftCard);
        }
        public static object GetGiftCardQuantityCurrency(long giftCardId)
        {
            return GiftCardDataAccess.GetGiftCardById(giftCardId);
        }
        public static User GetSenderUser(long senderId)
        {
            return UserDataAccess.GetUserById(senderId);
        }
    }
}
